import { observable, action } from "mobx";
import pagination from "@/stores/common/Pagination";
import * as InfoApi from "@/service/api/HumanRecognitionTrackingApi";

class HumanRecognitionTrackingStore {
  @observable list = [{ key: "key_478qwe45", id: "1", name: "你好" }];
  @observable item;
  @observable pagination = new pagination();
  @observable firstImgBase64 = "";
  @observable uploadImageWidth=undefined;
  @observable lenghtOfHumanPage=0;//人页面push进去的图片的长度


  @action dellenghtOfHumanPage = (lenghtOfHumanPage) => {
    this.lenghtOfHumanPage = lenghtOfHumanPage-1;
  }
  @action addlenghtOfHumanPage = (lenghtOfHumanPage) => {
    this.lenghtOfHumanPage = lenghtOfHumanPage+1;
  }
 @action resetlenghtOfHumanPage = () => {
    this.lenghtOfHumanPage = 0;
  }

  @action changeUploadImageWidth = (uploadImageWidth) => {
    this.uploadImageWidth = uploadImageWidth;
  }

  @action changeFirstImgBase64 = (firstImgBase64) => {
    this.firstImgBase64 = firstImgBase64;
  }

  @action saveItem = obj => {
    const that = this;
    InfoApi.ADDITEM(obj).then(rs => {
      that.hiddenDialog();
    });
  };

  @action upItem = obj => {
    const that = this;
    InfoApi.UPITEM(obj).then(rs => {
      that.hiddenDialog();
    });
  };
  @action hiddenDialog = () => {
    this.item = undefined;
  };
  @action addShow = () => {
    this.item = {};
  };
  @action editShow = item => {
    this.item = item;
  };
  @action removeItem = id => {
    const that = this;
    InfoApi.DELITEM({ id }).then(rs => {
      that.getList();
    });
  };
  @action showPropup = bool => {
    this.item = undefined;
  };
  @action hideProup = () => {
    this.item = undefined;
    this.getList();
  };
  @action updateItem = info => {
    const that = this;
    InfoApi.UPITEM(info).then(rs => {
      that.hideProup();
    });
  };
  @action init = () => {
    this.pagination.getList = this.getList;
    this.getList();
  };
  @action setList = data => {
    this.pagination.init(data);
    this.list = data.data;
  };
  @action getList = () => {
    const that = this;
    var params = {
      currentPage: this.pagination.currentPage,
      pageSize: this.pagination.pageSize
    };
    InfoApi.GETLIST(params).then(rs => {
      if (rs.success) {
        that.setList(rs);
      }
    });
  };
}

export default new HumanRecognitionTrackingStore();
